Skip to content

fix(utils)!: remove the evaluation helpers from tools.hpp - #262

Merged
gouyt13 merged 2 commits into
dev/0.9from
fix/remove-eval-helpers
Nov 21, 2026
Merged

gouyt13 merged 2 commits into
dev/0.9from
fix/remove-eval-helpers

Conversation

@gouyt13

@gouyt13 gouyt13 commented Nov 21, 2026

Copy link
Copy Markdown
Member

rabitqlib/utils/tools.hpp is an installed header, and two evaluation helpers in it had undefined behavior:

  • distance_ratio formed data + id * dim for every result ID without a check, so a missing result (kNoId from IvfIndex/HnswIndex/SymqgIndex, or kPidMax from the lower-level searches) read out of bounds (ASan: heap-buffer-overflow).
  • horizontal_avg read data[0] on empty input, read past shorter rows, and divided signed sums by a size_t: horizontal_avg<int> of three rows of -1 returned 1431655764.

Neither is index functionality. distance_ratio has no callers, and horizontal_avg's only callers are the three C++ querying samples, so this removes both instead of fixing them. A safe distance_ratio would also need a point-count parameter, which changes its signature anyway.

Change

  • Remove distance_ratio and horizontal_avg from tools.hpp, with the <cmath>, <queue> and <vector> includes only they used.
  • The querying samples average their measurements with querying_example::column_averages in the new sample/cpp/querying_example.hpp. On the samples' rectangular float matrices it gives the same results as before, bit for bit.
  • Release notes: an entry under C++ changes, which also says that code relying on RaBitQ headers for std::priority_queue must include <queue>. <vector> and <cmath> still come through other headers.

Compatibility
Code calling rabitqlib::distance_ratio or rabitqlib::horizontal_avg no longer compiles; 0.9 is a breaking release. zvec, the known C++ downstream, uses neither and does not use std::priority_queue through RaBitQ headers (checked by code search and a clone of its default branch).

Checks run (Linux x86-64, native optimization off)

  • Full build (tests, samples, Python bindings) and a core-only build without OpenMP: C++ suites 616 and 203 passed, with 1 environment skip.
  • Installed consumer tests and tests/core_consumer/run.cmake with OpenMP off.
  • Every first-party header compiled alone, on the base and with this change.
  • check-includes.sh: the same diagnostics as the base.
  • Indexing then querying with the three C++ samples on 3000 points in 64 dimensions. For IVF and SymphonyQG, the printed settings and recall match the base binaries on the same index files.
  • check-format.sh, full check-tidy.sh, mkdocs build --strict, git diff --check.

There are no new tests: removing the helpers leaves no behavior to test, and the sample helper is covered by building the samples.

distance_ratio and horizontal_avg in the installed header
rabitqlib/utils/tools.hpp had undefined behavior. distance_ratio formed
data + id * dim for every result ID, so a missing result (kNoId or
kPidMax, which the index searches use for padding) read out of bounds.
horizontal_avg read data[0] on empty input, read past shorter rows, and
divided signed sums by a size_t, so horizontal_avg<int> of three rows of
-1 gave 1431655764.

Neither is index functionality: distance_ratio has no callers, and
horizontal_avg's only callers are the C++ querying samples. Remove both,
and the <cmath>, <queue> and <vector> includes only they used. The
samples average their measurements with querying_example::column_averages
in sample/cpp/querying_example.hpp. The release notes record the removal.
@github-actions github-actions Bot added the release:fixed Release category managed from the PR title label Nov 21, 2026
@gouyt13 gouyt13 added the release:breaking Breaking change; listed first in release notes (set by hand) label Nov 21, 2026
@gouyt13
gouyt13 merged commit 97eb05e into dev/0.9 Nov 21, 2026
34 checks passed
@gouyt13
gouyt13 deleted the fix/remove-eval-helpers branch November 21, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:breaking Breaking change; listed first in release notes (set by hand) release:fixed Release category managed from the PR title

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant